package demo1;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s1 = scanner.next();
            String s2 = scanner.next();
            int n = s1.length(), m = s2.length();
            int[][] dp = new int[n+1][m+1];
            for(int i = 1; i<=n; i++) {
                for(int j = 1; j<=m; j++) {
                    if(s1.charAt(i-1)== s2.charAt(j-1)) {
                        dp[i][j] = Math.max(dp[i][j], dp[i-1][j-1]+1);
                    }else {
                        dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
                    }
                }
            }

            System.out.println(dp[n][m]);
        }
    }
}
